'''
日历控件
和使时间
'''

import sys

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class MyCalendar(QWidget):
    def __init__(self):
        super(MyCalendar, self).__init__()
        self.initUI()
    def initUI(self):

        self.cal = QCalendarWidget(self)
        self.cal.setMinimumDate(QDate(1988, 1, 1))
        self.cal.setMaximumDate(QDate(2088, 1, 1))


        self.label =QLabel(self)
        data = self.cal.selectedDate()
        self.label.setText((data.toString("yyyy-MM-dd dddd")))
        self.label.move(20, 300)

        self.cal.setGridVisible(True)
        self.cal.move(20,20)
        self.cal.clicked.connect(self.showDate)
        self.resize(600, 600)


        layout = QVBoxLayout()

        dateTimeEdit1 = QDateTimeEdit()
        dateTimeEdit2 = QDateTimeEdit(QDateTime.currentDateTime())

        dataEdit = QDateTimeEdit(QDate.currentDate())
        timeEdit = QDateTimeEdit(QTime.currentTime())

        dateTimeEdit1.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
        dateTimeEdit2.setDisplayFormat("yyyy/MM/dd HH-mm-ss")

        dataEdit.setDisplayFormat("yyyy.MM.dd")
        timeEdit.setDisplayFormat('HH:mm:ss')

        layout.addWidget(dateTimeEdit1)
        layout.addWidget(dateTimeEdit2)
        layout.addWidget(dataEdit)
        layout.addWidget(timeEdit)
        self.setLayout(layout)
        self.setWindowTitle('calendar')

    def showDate(self, data):
        self.label.setText((data.toString("yyyy-MM-dd dddd")))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MyCalendar()
    ex.show()
    sys.exit(app.exec_())